<template>
	<view class="content">
		<view class="" v-if="list.length>0">
			<view class="p2432 bgf br16 mb24" v-for="(item,index) in list" @click="seleceAddress(item)">
				<view class="flex_x">
					<view class="address addressa flex_c fs24 c2a7">{{item.contact.charAt(0)}}</view>
					<view class="flex1 mlr24">
						<view class="flex_x">
							<view class="c3 fw500 fs32">{{item.contact}}</view>
							<view class="c9 fs24 ml24">{{item.telephone}}</view>
							<view class="defaultTag c2a7 flex_c fs22 ml16" v-if="item.is_default == 1">默认</view>
						</view>
						<view class="c3 fs26 mt16">{{item.province}} {{item.city}}{{item.district}} {{item.address}}
						</view>
					</view>
					<view class="address">
						<image @click.stop="eitdAdderss(item)" class="eitd_img" src="/static/my/user/address/eitd.png"
							mode="">
						</image>
					</view>
				</view>
				<view class="line mtb24"></view>
				<view class="c9 fs24 flex_btw">
					<view class="flex_x" @click.stop="setDefaultCity(item)">
						<view class="flex_c">
							<image v-if="item.is_default == 1" class="xz_img" src="/static/my/user/address/xz.png"
								mode="">
							</image>
							<image v-else class="xz_img" src="/static/my/user/address/wxz.png" mode=""></image>
						</view>
						<view class="ml20">默认地址</view>
					</view>
					<view class="" @click.stop="delAddress(item,index)">删除</view>
				</view>
			</view>
		</view>
		<view class="" v-else>
			<u-empty mode="address" icon="http://cdn.uviewui.com/uview/empty/address.png">
			</u-empty>
		</view>
		<view class="addCity flex_y">
			<view class="btn flex_c cf fs26 fw500" @click="addAdderss">+新增地址</view>
		</view>

		<!-- 弹窗 -->
		<view class="">
			<view class="">
				<u-modal :show="delShow" title="提示" showCancelButton confirmColor='#2A71C0' @cancel='delShow = false'
					@confirm='confirmDel'>
					<view class="slot-content">
						<view class="c6 fs30">确定删除地址?</view>
					</view>
				</u-modal>
			</view>
		</view>
		<pullUp :status='state'></pullUp>
	</view>
</template>

<script>
	import {
		pageSize
	} from '@/components/minxins.js' //引入minxins
	export default {
		components: {},
		mixins: [pageSize],
		data() {
			return {
				list: [], //地址列表
				next_list: [], //下一页地址列表
				delShow: false, //删除弹窗
				del_id: '', //删除id
				del_index: '', //删除的下标

				active: '', //1会员商品选择地址
				id: '', //选择的地址 用于删除地址时候删除选选择的地址
			}
		},

		onLoad(options) {
			if (options.id) {
				this.id = options.id
			}
			this.method_name = 'getUserAddress'
		},
		onShow() {
			this.getList();
		},
		methods: {
			setDefaultCity(item) { //设置默认地址
				this.$api.setDefaultAddress({
					id: item.id
				}).then(res => {
					if (res.code == 1) {
						this.getList()
					} else {
						uni.$u.toast(res.msg)
					}
				})
			},
			delAddress(item, index) { //删除地址
				this.del_id = item.id
				this.del_index = index
				this.delShow = true
			},
			confirmDel() { //确认删除
				this.$api.delAddress({
					id: this.del_id
				}).then(res => {
					if (res.code == 1) {
						if (this.id == this.del_id) {
							uni.$emit('sendCity', '')
						}
						this.del_list(this.del_index)
						// this.getList()
					} else {
						uni.$u.toast(res.msg)
					}
					this.delShow = false
				})
			},
			addAdderss() { //添加地址
				uni.navigateTo({
					url: '/pages/user/my/address/addAddress/addAddress?title=添加地址'
				})
			},
			eitdAdderss(item) { //编辑地址
				uni.setStorage({
					key: 'address',
					data: item,
					success: () => {
						uni.navigateTo({
							url: '/pages/user/my/address/addAddress/addAddress?title=编辑地址&flag=2'
						})
					}
				})
			},
			seleceAddress(item) { //选择地址
				uni.$emit('sendCity', item)
				uni.navigateBack()
			}
		},
		computed: {

		},
		watch: {

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 40upx 32upx calc(120upx + env(safe-area-inset-bottom)) 32upx;

		.address {
			width: 56upx;
		}

		.addressa {
			width: 56upx;
			height: 56upx;
			border-radius: 50%;
			background: rgba(42, 113, 192, 0.1);
		}

		.eitd_img {
			width: 30upx;
			height: 30upx;
		}

		.defaultTag {
			width: 66upx;
			height: 36upx;
			background: rgba(42, 113, 192, 0.15);
			border-radius: 4upx;
		}

		.line {
			height: 1upx;
			background-color: #d8d8d8;
		}

		.xz_img {
			width: 28upx;
			height: 28upx;
		}

		.addCity {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #fff;
			padding: 10upx 0 calc(30upx + env(safe-area-inset-bottom)) 0;

			.btn {
				width: 557upx;
				height: 74upx;
				background: #2A71C0;
				border-radius: 40upx;
			}
		}
	}
</style>
